package model.builders;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import model.Graph;
import model.Itinerary;

public class ItineraryBuilder {

    private final Graph graph;
    private int tab[];
    
    public ItineraryBuilder(Graph graph) {
        this.graph = graph;
        this.tab = new int[graph.getSize()];
    }

    // start from "0"
    public ItineraryBuilder fill() {
        if(tab.length < 2) {            
            return this;
        }
        List<Integer> list = new LinkedList<>();        
        for (int i = 0; i < tab.length - 1; i++) {
            list.add(i + 1);
        }
        Collections.shuffle(list);
        tab[0] = 0;
        for (int i = 1; i < tab.length; i++) {
            tab[i] = list.get(i - 1);
        }
        return this;
    }

    public Itinerary build() {
        return new Itinerary(tab, graph);
    }
}
